#ifndef __PLAY_UI_LOGIC_H__
#define __PLAY_UI_LOGIC_H__
#include "UIPlayLayout.h"
#include "UICannonLayout.h"
#include "UIMarkLayout.h"
#include "../include/IGameLogic.h"
namespace fishingjoy
{
	namespace ui
	{
		class CPlayUILogic
		{
			UI_PlayLayout m_PlayLayout;
			UI_CannonLayout m_CannonLayout;
			UI_MarkLayout m_MarkLayout;
			logic::IGameLogic* m_pGameLogic;
			int m_iCannonLevel;
		public:
			CPlayUILogic(logic::IGameLogic* p,cocos2d::CCLayer* pParent)
			{
				m_pGameLogic = p;
				pParent->addChild(&m_PlayLayout);
				m_PlayLayout.setVisible(false);
				base::Delegate<void(void)> egs(this,&CPlayUILogic::slot_EnterGame);;
				m_pGameLogic->Event_EnterGameSuccessed+=egs;

				base::Delegate<void(void)> gps(this,&CPlayUILogic::slot_CannonAdd);;
				m_CannonLayout.Event_CannonAdd += gps;

				base::Delegate<void(void)> ges(this,&CPlayUILogic::slot_CannonReduce);
				m_CannonLayout.Event_CannonReduce += ges;

				base::Delegate<void(const CCPoint&,float)> tes(this,&CPlayUILogic::slot_TapScreen);
				m_CannonLayout.Event_TapScreen += tes;

				base::Delegate<void(void)> mes(this,&CPlayUILogic::slot_MarkChange);
				m_pGameLogic->Event_MarkChange+= mes;

				base::Delegate<void(float,float,int)> fes(this,&CPlayUILogic::slot_FishDie);
				m_pGameLogic->Event_FishDie += fes;

				m_PlayLayout.addChild(&m_CannonLayout);
				m_CannonLayout.setPositionX(258);
				m_CannonLayout.setPositionY(25);


				m_PlayLayout.addChild(&m_MarkLayout);
				m_MarkLayout.setPositionX(20);
				m_MarkLayout.setPositionY(-1);

				m_iCannonLevel = 1;
			}
		private:
			void slot_EnterGame()
			{
				m_PlayLayout.setVisible(true);
				m_MarkLayout.changeNum(m_pGameLogic->getMark());
			}

			void slot_CannonAdd()
			{
				m_iCannonLevel++;
				if(m_iCannonLevel > 5)
					m_iCannonLevel = 1;
				m_CannonLayout.setCannonLevel(m_iCannonLevel);
				m_pGameLogic->setLevel(m_iCannonLevel);
				m_pGameLogic->playEffect("SwitchSilo.wav");
			}

			void slot_CannonReduce()
			{
				m_iCannonLevel--;
				if(m_iCannonLevel < 1)
					m_iCannonLevel = 5;
				m_CannonLayout.setCannonLevel(m_iCannonLevel);
				m_pGameLogic->setLevel(m_iCannonLevel);
				m_pGameLogic->playEffect("SwitchSilo.wav");
			}

			void slot_TapScreen(const CCPoint& pt,float dir)
			{
				printf("pt:(%f,%f),dir:%f \n",pt.x,pt.y,dir);
				m_pGameLogic->onShoot(pt.x,pt.y,dir);
			}

		public:
			void slot_FishDie(float x,float y,int mar)
			{
				printf("fish die event.\n");
			}

			void slot_MarkChange()
			{
				m_MarkLayout.changeNum(m_pGameLogic->getMark());
			}
		};
	}
}
#endif